package cn.itcast.tanhua.mytanhuaserver.controller;

import cn.itcast.tanhua.mytanhuaserver.service.TodayBestService;
import cn.itcast.tanhua.vo.PageResult;
import cn.itcast.tanhua.vo.RecommendUserQueryParam;
import cn.itcast.tanhua.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 郭文亮
 * @since 2021/11/25 19:00
 */
@RestController
@RequestMapping("tanhua")
@Slf4j
public class TodayBestController {

    @Autowired
    private TodayBestService todayBestService;

    /**
     * 查询今日佳人
     * @param token 包含当前用户id
     * @return 成功返回200和今日佳人信息，失败返回500
     */
    @GetMapping("todayBest")
    public ResponseEntity<TodayBest> getTodayBest(@RequestHeader("Authorization") String token){
        try {
            TodayBest todayBest = this.todayBestService.getTodayBest(token);
            if (null != todayBest) {
                return ResponseEntity.ok(todayBest);
            }
        } catch (Exception e) {
            log.error("查询今日佳人出错~ token = " + token, e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * 查询推荐用户列表
     * @param token 存放当前用户的id
     * @param queryParam 存放查询的条件
     * @return 查询的用户列表结果
     */
    @GetMapping("recommendation")
    public ResponseEntity<PageResult> queryRecommendation(@RequestHeader("Authorization") String token,
                                                          RecommendUserQueryParam queryParam){
        try {
            PageResult pageResult = this.todayBestService.queryRecommendation(token,queryParam);
            if (null != pageResult) {
                // 查询到数据，将数据返回，并返回状态码200
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            log.error("查询推荐用户列表出错~ token = " + token, e);
        }
        // 查询不到数据，返回状态码500
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
